<%-- 
Document   : detail
Created on : 22.11.2014, 14:50:29
Author     : Martin Klvaňa, 395893
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><fmt:message key="machine" /> <c:out value="${model.machine.id}"/></title>
    </head>
    <body>
        <div class="container">
            <c:if test="${null == model}">
                <img src="<c:url value="/resources/pictures/error.png" />" title="<fmt:message key="machine.index.noMachines" />" />
                <b><fmt:message key="machine.index.noMachines" /></b>
            </c:if>
            <c:if test="${null != model}">
                <c:if test="${null == model.machine}">
                    <img src="<c:url value="/resources/pictures/error.png" />" title="<fmt:message key="machine.index.noMachines" />" />
                    <b><fmt:message key="machine.index.noMachines" /></b>
                </c:if>

                <c:if test="${null != model.machine}">
                   <button onclick="location.href = '<c:url value="/machine/index"/>'" class="btn btn-default"><fmt:message key="back" /></button>
                   <h1><fmt:message key="machine" /> <c:out value="${model.machine.model}"/> <c:out value="${model.machine.brand}"/></h1>
                    <sec:authorize access="hasRole('ROLE_ADMIN')">
                        <div>
                            <a href="<c:url value="/machine/remove/${model.machine.id}"/>" onclick="return confirm('<fmt:message key="machine.remove.confirm" />')">
                                <img src="<c:url value="/resources/pictures/remove.png" />" title="<fmt:message key="machine.remove" />" /> <fmt:message key="machine.remove" />
                            </a>
                        </div>
                    </sec:authorize>  


                    <table class="table table-striped">
                        <tr>
                            <td><b><fmt:message key="machine.model" /></b></td>
                            <td><c:out value="${model.machine.model}"/></td>
                        </tr>
                        <tr>
                            <td><b><fmt:message key="machine.code" /></b></td>
                            <td><c:out value="${model.machine.code}"/></td>
                        </tr>
                        <tr>
                            <td><b><fmt:message key="machine.brand" /></b></td>
                            <td><c:out value="${model.machine.brand}"/></td>
                        </tr>
                        <tr>
                            <td><b><fmt:message key="machine.yearOfProduction" /></b></td>
                            <td><c:out value="${model.machine.yearOfProduction}"/></td>
                        </tr>
                    </table>
                </c:if>
            </c:if>
        </div>

        <div class="container">
            <c:if test="${null != model.machine}">
                <div>
                    <h3><fmt:message key="revisions" /></h3>
                </div>

                <a href="<c:url value="/revision/add"/>">
                    <img src="<c:url value="/resources/pictures/add.png" />" title="<fmt:message key="revision.addNew" />" /> <fmt:message key="revision.addNew" />
                </a>


                <c:if test="${empty model.revisions}">
                    <fmt:message key="revision.norevisions" />
                </c:if>
                <c:if test="${not empty model.revisions}">

                    <form method="POST" class="form-inline" role="form">
                        <div class="form-group">
                            <label><fmt:message key="revision.searchFrom" /></label>
                            <input class="form-control" id="datepicker" name="startDate"/>
                        </div>
                        <div class="form-group">
                            <label><fmt:message key="revision.searchTo" /></label>
                            <input class="form-control" id="datepicker2" name="endDate"/>
                        </div>
                        <div class="form-group">
                            <input class="btn btn-default" type="submit" value="<fmt:message key="search"/>">
                        </div>
                    </form>

                    <table class="table table-striped">
                        <th>
                            <fmt:message key="detail" />
                        </th>
                        <th>
                            <fmt:message key="revision.description" />
                        </th>
                        <th>
                            <fmt:message key="revision.dateofrevision" />
                        </th>
                        <th>
                            <fmt:message key="revision.machine" />
                        </th>
                        <th>
                            <fmt:message key="edit" />
                        </th>
                        <c:forEach var="r" items="${model.revisions}">
                            <tr>
                                <td>
                                    <a href="<c:url value="/revision/detail/${r.id}"/>">
                                        <img src="<c:url value="/resources/pictures/detail.png" />" title="<fmt:message key="detail" />" /> <fmt:message key="detail" />
                                    </a>
                                </td>
                                <td>
                                    <c:out value="${r.description}"/>
                                </td>
                                <td>
                                    <c:out value="${r.dateOfRevision}"/>
                                </td>
                                <td>
                                    <c:out value="${r.machine}"/>
                                </td>
                                <td>
                                    <a href="<c:url value="/revision/edit/${r.id}"/>">
                                        <img src="<c:url value="/resources/pictures/edit.png" />" title="<fmt:message key="edit" />" /> <fmt:message key="edit" />
                                    </a>
                                </td>
                                <td>
                                    <a href="<c:url value="/revision/remove/${r.id}"/>">
                                        <img src="<c:url value="/resources/pictures/remove.png" />" title="<fmt:message key="remove" />" /> <fmt:message key="remove" />
                                    </a>
                                </td>                                
                            </tr>
                        </c:forEach>
                    </table>
                </c:if>
            </div>

            <div class="container">
                <div>
                    <h3><fmt:message key="rentals" /></h3>
                </div>

                <c:if test="${empty model.rentals}">
                    <fmt:message key="rental.notrentalsavailable" />
                </c:if>
                <c:if test="${not empty model.rentals}">

                    <table class="table table-striped">
                        <th>
                            <fmt:message key="detail" />
                        </th>
                        <th>
                            <fmt:message key="customer" />
                        </th>
                        <th>
                            <fmt:message key="rental.dateOfRent" />
                        </th>
                        <th>
                            <fmt:message key="rental.duration" />
                        </th>
                        <th>
                            <fmt:message key="rental.dateOfReturn" />
                        </th>
                        <th>
                            <fmt:message key="edit" />
                        </th>
                        <c:forEach var="r" items="${model.rentals}">
                            <tr>
                                <td>
                                    <a href="<c:url value="/rental/detail/${r.id}"/>">
                                        <img src="<c:url value="/resources/pictures/detail.png" />" title="<fmt:message key="detail" />" /> <fmt:message key="detail" />
                                    </a>
                                </td>
                                <td>
                                    <a href="<c:url value="/customer/detail/${r.customer.id}"/>"><c:out value="${r.customer.firstName}"/> <c:out value="${r.customer.lastName}"/> </a>
                                </td>
                                <td>
                                    <c:out value="${r.dateOfRent}"/>
                                </td>
                                <td>
                                    <c:out value="${r.duration}"/>
                                </td>
                                <td>
                                    <c:out value="${r.dateOfReturn}"/>
                                </td>
                                <td>
                                    <a href="<c:url value="/rental/edit/${r.id}"/>">
                                        <img src="<c:url value="/resources/pictures/edit.png" />" title="<fmt:message key="edit" />" /> <fmt:message key="edit" />
                                    </a>
                                </td>
                            </tr>
                        </c:forEach>
                    </table>
                </c:if>
            </div>   
        </c:if>
    </body>
</html>
